package com.ruoyi.web.controller.system;

import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;
import javax.validation.constraints.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.vo.ZhcaSmallappVo;
import com.ruoyi.system.bo.ZhcaSmallappQueryBo;
import com.ruoyi.system.bo.ZhcaSmallappAddBo;
import com.ruoyi.system.bo.ZhcaSmallappEditBo;
import com.ruoyi.system.service.IZhcaSmallappService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 小程序Controller
 *
 * @author ruoyi
 * @date 2021-07-27
 */
@Validated
@Api(value = "小程序控制器", tags = {"小程序管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/system/smallapp")
public class ZhcaSmallappController extends BaseController {

    private final IZhcaSmallappService iZhcaSmallappService;

    /**
     * 查询小程序列表
     */
    @ApiOperation("查询小程序列表")
    //@PreAuthorize("@ss.hasPermi('system:smallapp:list')")
    @GetMapping("/list")
    public TableDataInfo<ZhcaSmallappVo> list(@Validated ZhcaSmallappQueryBo bo) {
        return iZhcaSmallappService.queryPageList(bo);
    }

    /**
     * 导出小程序列表
     */
    @ApiOperation("导出小程序列表")
	//@PreAuthorize("@ss.hasPermi('system:smallapp:export')")
    @Log(title = "小程序", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<ZhcaSmallappVo> export(@Validated ZhcaSmallappQueryBo bo) {
        List<ZhcaSmallappVo> list = iZhcaSmallappService.queryList(bo);
        ExcelUtil<ZhcaSmallappVo> util = new ExcelUtil<ZhcaSmallappVo>(ZhcaSmallappVo.class);
        return util.exportExcel(list, "小程序");
    }

    /**
     * 获取小程序详细信息
     */
    @ApiOperation("获取小程序详细信息")
	//@PreAuthorize("@ss.hasPermi('system:smallapp:query')")
    @GetMapping("/{id}")
    public AjaxResult<ZhcaSmallappVo> getInfo(@NotNull(message = "主键不能为空")
                                                  @PathVariable("id") Long id) {
        return AjaxResult.success(iZhcaSmallappService.queryById(id));
    }

    /**
     * 新增小程序
     */
    @ApiOperation("新增小程序")
	//@PreAuthorize("@ss.hasPermi('system:smallapp:add')")
    @Log(title = "小程序", businessType = BusinessType.INSERT)
    @RepeatSubmit
    @PostMapping()
    public AjaxResult<Void> add(@Validated @RequestBody ZhcaSmallappAddBo bo) {
        return toAjax(iZhcaSmallappService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改小程序
     */
    @ApiOperation("修改小程序")
	//@PreAuthorize("@ss.hasPermi('system:smallapp:edit')")
    @Log(title = "小程序", businessType = BusinessType.UPDATE)
    @RepeatSubmit
    @PutMapping()
    public AjaxResult<Void> edit(@Validated @RequestBody ZhcaSmallappEditBo bo) {
        return toAjax(iZhcaSmallappService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除小程序
     */
    @ApiOperation("删除小程序")
	//@PreAuthorize("@ss.hasPermi('system:smallapp:remove')")
    @Log(title = "小程序" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] ids) {
        return toAjax(iZhcaSmallappService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
